package cn.lzx.transaction.inter.impl;

import cn.lzx.domain.Customer;
import cn.lzx.domain.CustomerJpaRepository;
import cn.lzx.transaction.inter.CustomerServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by lizhenxing on 2017/8/31.
 */

@Service
public class CustomerServiceInterImpl implements CustomerServiceInter {


    @Autowired
    private CustomerJpaRepository customerJpaRepository;


    @Override
    public void buy(Long userId,Long price){
        Customer customer = customerJpaRepository.findOne(userId);
        Long remainder = customer.getMoney()-price;
        customer.setMoney(remainder);
        save(customer);
    }

    private void save(Customer customer){
        customerJpaRepository.save(customer);
    }
}
